﻿namespace instamuz.DataAccess.Queries.PostQueries
{
    using System.Collections.Generic;
    using System.Linq;
    using Domain.Entities;
    using IndyCode.Infrastructure.Domain;
    using IndyCode.Infrastructure.NHibernate;
    using instamuz.Application.Criterias.Post;

    public class FindFeedForAccountQuery : LinqQueryBase<Post, FindFeedForAccountCriteria, IEnumerable<Post>>
    {
        public FindFeedForAccountQuery(ILinqProvider linq) : base(linq)
        {
        }

        public override IEnumerable<Post> Ask(FindFeedForAccountCriteria criterion)
        {
            return Query
                .Where(x => x.Account != null)
                .Where(x => criterion.Account.Following.Contains(x.Account))
                .OrderByDescending(x => x.CreatedAt)
                .ToList();
        }
    }
}